package com.q.tqb.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.q.tqb.R;
import com.q.tqb.model.PromotionInfo;
import com.q.tqb.util.StringUtil;
import com.q.tqb.view.CircleImageView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PromtionAdapter extends RecyclerView.Adapter<PromtionAdapter.ViewHolder> {

    private ArrayList<PromotionInfo> mRedPersonDatas;
    private Context mContext;
    private int type;


    public PromtionAdapter(Context context, ArrayList<PromotionInfo> mRedPersonDatas) {
        this.mRedPersonDatas = mRedPersonDatas;
        this.mContext = context;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_promotion, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        PromotionInfo getRedPersonData = mRedPersonDatas.get(position);

        holder.mTvId.setText(position + 1 + "");

        holder.mTvName.setText(getRedPersonData.getUserInfo().getNickname());

        Glide
                .with(mContext)
                .load(getRedPersonData.getUserInfo().getHeader())
                .error(R.drawable.ic_head)
                .placeholder(R.drawable.ic_head)
                .dontAnimate()
                .into(holder.mIvHead);

        if (type == 3 || type == 2 || type == 4) {
            holder.mTvMoney.setText(getRedPersonData.getSum()+ "位");
        } else if (type == 1) {
            holder.mTvMoney.setText(getRedPersonData.getMoney()+ "元");
        }


    }

    @Override
    public int getItemCount() {
        return mRedPersonDatas.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_id)
        TextView mTvId;
        @BindView(R.id.iv_head)
        CircleImageView mIvHead;
        @BindView(R.id.tv_name)
        TextView mTvName;
        @BindView(R.id.tv_money)
        TextView mTvMoney;

        ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}